package cn.edu.zafu.bigdata.llc;

public class Cube {
    // 属性：长、宽、高
    private final double length;
    private final double width;
    private final double height;

    // 构造方法
    public Cube(double length, double width, double height) {
        this.length = length;
        this.width = width;
        this.height = height;
    }

    // 获取长
    public double getLength() {
        return length;
    }

    // 获取宽
    public double getWidth() {
        return width;
    }

    // 获取高
    public double getHeight() {
        return height;
    }

    // 重写equals方法
    @Override
    public boolean equals(Object obj) {
        // 判断是否为同一对象
        if (this == obj) {
            return true;
        }
        // 判断是否为空或类型不同
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        // 类型转换
        Cube cube = (Cube) obj;
        // 判断长、宽、高是否相等
        return Double.compare(cube.length, length) == 0 &&
                Double.compare(cube.width, width) == 0 &&
                Double.compare(cube.height, height) == 0;
    }

    // 重写hashCode方法（通常与equals方法一起重写）
    @Override
    public int hashCode() {
        // 使用一个质数作为乘数，并将三个属性的哈希值组合起来
        int result;
        long temp;
        temp = Double.doubleToLongBits(length);
        result = (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(width);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(height);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        return result;
    }
}